package io.renren.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.renren.entity.GroupPersonnel;
import io.renren.entity.Personnel;
import io.renren.entity.WeixinUser;
import io.renren.service.GroupPersonnelService;
import io.renren.service.PersonnelService;
import io.renren.service.WeixinUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import io.renren.entity.WxuserPersonal;
import io.renren.service.WxuserPersonalService;
import io.renren.utils.PageUtils;
import io.renren.utils.R;


/**
 * 班主与下属员工
 * 
 * @author zk
 * @email zk13899@163.com
 * @date 2017-10-19 09:24:14
 */
@Controller
@RequestMapping("wxuserpersonal")
public class WxuserPersonalController {
	@Autowired
	private WxuserPersonalService wxuserPersonalService;
	@Autowired
	private PersonnelService personnelService;
	@Autowired
	private GroupPersonnelService groupPersonnelService;
	@Autowired
	private WeixinUserService weixinUserService;
	
	@RequestMapping("/wxuserpersonal.html")
	public String list(){
		return "wxuserpersonal/wxuserpersonal.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("wxuserpersonal:list")
	public R list(Integer page, Integer limit){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		
		//查询列表数据
		List<WxuserPersonal> wxuserPersonalList = wxuserPersonalService.queryList(map);
		int total = wxuserPersonalService.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(wxuserPersonalList, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}
	/* 分组列表 */
	@ResponseBody
	@RequestMapping("/groupPersonnel/list")

	public R personlist() {
		Map<String, Object> map = new HashMap<>();
		List<GroupPersonnel> listGroupPersonnel = groupPersonnelService.queryList(map);

		return R.ok().put("listGroupPersonnel", listGroupPersonnel);
	}

	/* 班主列表 */
	@ResponseBody
	@RequestMapping("/wxuser/list")

	public R wxuserist() {
		Map<String, Object> map = new HashMap<>();
		List<WeixinUser> listWxUser = weixinUserService.queryList(map);

		return R.ok().put("listWxUser", listWxUser);
	}
	/* 人员列表 */
	@ResponseBody
	@RequestMapping("/person/list")

	public R person() {
		Map<String, Object> map = new HashMap<>();
		List<Personnel> listPerson = personnelService.queryList(map);

		return R.ok().put("listPerson", listPerson);
	}
	/* 基站列表 */
	@ResponseBody
	@RequestMapping("/person/list/{idGroup}")

	public R personlist(@PathVariable("idGroup") Integer idGroup,String str) {
		Map<String, Object> map = new HashMap<>();
		map.put("idGroup",idGroup);
		map.put("str", str);
		List<Personnel> listPerson = personnelService.queryListByIdGroupIdWxUser(map);

		return R.ok().put("listPerson", listPerson);
	}
	
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("wxuserpersonal:info")
	public R info(@PathVariable("id") Integer id){
		WxuserPersonal wxuserPersonal = wxuserPersonalService.queryObject(id);
		
		return R.ok().put("wxuserPersonal", wxuserPersonal);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("wxuserpersonal:save")
	public R save(@RequestBody WxuserPersonal wxuserPersonal){
		wxuserPersonalService.save(wxuserPersonal);
		
		return R.ok();
	}

	/**
	 * 批量保存
	 */
	@ResponseBody
	@RequestMapping("/addBatch")
	public R saves(@RequestBody List<WxuserPersonal> list){

		wxuserPersonalService.addBatch(list);

		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("wxuserpersonal:update")
	public R update(@RequestBody WxuserPersonal wxuserPersonal){
		wxuserPersonalService.update(wxuserPersonal);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("wxuserpersonal:delete")
	public R delete(@RequestBody Integer[] ids){
		wxuserPersonalService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
